package com.gitee.qdbp.jdbc.tags;

import java.io.IOException;
import com.gitee.qdbp.staticize.exception.TagException;
import com.gitee.qdbp.staticize.tags.base.BaseTag;
import com.gitee.qdbp.staticize.tags.base.NextStep;

/**
 * 读取配置值的标签
 *
 * @author zhaohuihua
 * @version 20210914
 */
public class ConfigValueTag extends BaseTag {

    /** 配置项KEY **/
    private String key;
    /** 保存配置值的变量名 **/
    private String var;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getVar() {
        return var;
    }

    public void setVar(String var) {
        this.var = var;
    }

    @Override
    public NextStep doHandle() throws TagException, IOException {
        // ${db.config.get('recursive.keyword')}
        Object value = this.getStackValue("db.config.get('" + key + "')", Object.class);
        if (var == null) {
            print(value);
            return NextStep.SKIP_BODY;
        } else {
            this.addStackValue(var, value);
            return NextStep.EVAL_BODY;
        }
    }
}
